import request from '@/utils/request'

export function getDepartmentUserList({ page, pageSize, query }) {
  return request({
    url: `/departments/${page}/${pageSize}`,
    method: 'get',
    params: query
  })
}

// 部门新增
export function addDepartment(data) {
  return request({
    url: `departments`,
    method: 'post',
    data
  })
}

// 部门详情
export function detailDepartment(id) {
  return request({
    url: `departments/${id}`,
    method: 'get'
  })
}

// 部门编辑
export function editDepartment(data) {
  return request({
    url: `departments/${data.id}`,
    method: 'put',
    data
  })
}

// 部门删除
export function delDepartment(id) {
  return request({
    url: `departments/${id}`,
    method: 'delete'
  })
}

// 查询人员列表
export function getUserList({ page, pageSize, query }) {
  return request({
    url: `users/${page}/${pageSize}`,
    method: 'get',
    params: query
  })
}

// 用户新增
export function addUser(data) {
  return request({
    url: `users`,
    method: 'post',
    data
  })
}

// 用户详情
export function detailUser(id) {
  return request({
    url: `users/${id}`,
    method: 'get'
  })
}

// 用户编辑
export function editUser(data) {
  return request({
    url: `users/${data.id}`,
    method: 'put',
    data
  })
}

// 用户重置密码
export function resetPassword(id, data) {
  return request({
    url: `users/reset_password/${id}`,
    method: 'POST',
    data
  })
}

// 用户删除
export function delUser(id) {
  return request({
    url: `users/${id}`,
    method: 'delete'
  })
}

// 启用/停用用户
export function editUserStatus(id, status) {
  return request({
    url: `users/edit_status/${id}/${status}`,
    method: 'put'
  })
}

// 查询浏览记录
export function viewHistory({ page, pageSize, query }) {
  return request({
    url: `view_history/newest/${page}/${pageSize}`,
    method: 'get',
    params: query
  })
}
